package com.vpx.server.mapper.system;

import com.vpx.server.framework.base.BaseMapper;
import com.vpx.server.bean.entity.SysRole;
import com.vpx.server.bean.order.system.SysRolePageOrder;
import com.vpx.server.framework.utils.SqlUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;

/**
 * @author liuks
 * @title: vpx
 * @module 角色管理
 * @description: 角色管理Mapper
 * @date 2021/9/9
 */
public interface SysRoleMapper extends BaseMapper<SysRole> {

    /**
     * 查询所有的角色
     * @return
     */
    @Select("select * from sys_role")
    List<SysRole> queryAllSysRole();

    /**
     * 分页查询
     * @param order
     * @return
     */
    @SelectProvider(type = SqlProvider.class, method = "pageQuery")
    List<SysRole> pageQuery(@Param("order") SysRolePageOrder order);

    class SqlProvider{
        public String pageQuery(@Param("order")SysRolePageOrder order){
            StringBuffer sb = new StringBuffer("select * from sys_role");
            Boolean where = false;
            if (StringUtils.isNotBlank(order.getRoleName())) {
                where = SqlUtils.appWhere(where, sb, "role_name like ('%'+#{order.roleName}+'%')");
            }
            sb.append(" order by create_time desc");
            return sb.toString();
        }
    }
}
